home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / CHAP09.ZIP / CHAP09 / PATRON / IDROPSRC.CPP < prev    next >
C/C++ Source or Header  |  1993-05-25  |  3KB  |  145 lines

  1. /*
  2.  * IDROPSRC.CPP
  3.  *
  4.  * Implementation of a DropSource object.
  5.  *
  6.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Software Design Engineer
  9.  * Microsoft Systems Developer Relations
  10.  *
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "patron.h"
  17.  
  18.  
  19.  
  20. /*
  21.  * CDropSource::CDropSource
  22.  * CDropSource::~CDropSource
  23.  *
  24.  * Constructor Parameters:
  25.  *  None
  26.  */
  27.  
  28. CDropSource::CDropSource(void)
  29.     {
  30.     m_cRef=0;
  31.     return;
  32.     }
  33.  
  34. CDropSource::~CDropSource(void)
  35.     {
  36.     return;
  37.     }
  38.  
  39.  
  40.  
  41.  
  42. /*
  43.  * CDropSource::QueryInterface
  44.  * CDropSource::AddRef
  45.  * CDropSource::Release
  46.  *
  47.  * Purpose:
  48.  *  IUnknown members for CDropSource object.
  49.  */
  50.  
  51. STDMETHODIMP CDropSource::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  52.     {
  53.     *ppv=NULL;
  54.  
  55.     //Any interface on this object is the object pointer.
  56.     if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IDropSource))
  57.         *ppv=(LPVOID)this;
  58.  
  59.     /*
  60.      * If we actually assign an interface to ppv we need to AddRef it
  61.      * since we're returning a new pointer.
  62.      */
  63.     if (NULL!=*ppv)
  64.         {
  65.         ((LPUNKNOWN)*ppv)->AddRef();
  66.         return NOERROR;
  67.         }
  68.  
  69.     return ResultFromScode(E_NOINTERFACE);
  70.     }
  71.  
  72.  
  73. STDMETHODIMP_(ULONG) CDropSource::AddRef(void)
  74.     {
  75.     return ++m_cRef;
  76.     }
  77.  
  78. STDMETHODIMP_(ULONG) CDropSource::Release(void)
  79.     {
  80.     ULONG           cRefT;
  81.  
  82.     cRefT=--m_cRef;
  83.  
  84.     if (0L==m_cRef)
  85.         delete this;
  86.  
  87.     return cRefT;
  88.     }
  89.  
  90.  
  91.  
  92.  
  93.  
  94. /*
  95.  * CDropSource::QueryDragContinue
  96.  *
  97.  * Purpose:
  98.  *  Determines whether to continue a drag operation or cancel it.
  99.  *
  100.  * Parameters:
  101.  *  fEsc            BOOL indicating that the ESC key was pressed.
  102.  *  grfKeyState     DWORD providing states of keys and mouse buttons.
  103.  *
  104.  * Return Value:
  105.  *  SCODE           DRAGDROP_S_CANCEL to stop the drag, DRAGDROP_S_DROP
  106.  *                  to drop the data where it is, or NOERROR to continue.
  107.  */
  108.  
  109. STDMETHODIMP CDropSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState)
  110.     {
  111.     if (fEsc)
  112.         return ResultFromScode(DRAGDROP_S_CANCEL);
  113.  
  114.     if (!(grfKeyState & MK_LBUTTON))
  115.         return ResultFromScode(DRAGDROP_S_DROP);
  116.  
  117.     return NOERROR;
  118.     }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. /*
  126.  * CDropSource::GiveFeedback
  127.  *
  128.  * Purpose:
  129.  *  Provides cursor feedback to the user since the source task
  130.  *  always has the mouse capture.  We can also provide any other
  131.  *  type of feedback above cursors if we so desire.
  132.  *
  133.  * Parameters:
  134.  *  dwEffect        DWORD effect flags returned from the last target.
  135.  *
  136.  * Return Value:
  137.  *  SCODE           NOERROR if you set a cursor yourself or
  138.  *                  DRAGDROP_S_USEDEFAULTCURSORS to let OLE do the work.
  139.  */
  140.  
  141. STDMETHODIMP CDropSource::GiveFeedback(DWORD dwEffect)
  142.     {
  143.     return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS);
  144.     }
  145.